<?php

class archives extends Model{
	
	//获取文章列表
	public function article($typeid='all',$page,$per_page,$orderby,$asc){
		$field = "id,typeid,flag,click,title,writer,litpic,pubdate,description";
		if($typeid=='all'){
			$query = "select ".$field." from dede_archives order by ".$orderby." ".$asc." limit ".($page-1)*$per_page.",".$per_page;
		}else{
			$query = "select ".$field." from dede_archives where typeid=".$typeid." order by ".$orderby." ".$asc." limit ".($page-1)*$per_page.",".$per_page;
		}
        $this->dsql->Execute('me',$query);
        $rows = array();
        while($row = $this->dsql->getarray()){
			$url=GetOneArchive($row['id']);
			$row['url'] = $url['arcurl'];
            $rows[] = $row;
        }
        return $rows;
	}
	
	//根据ID获取文章
	public function getartbyid($aid){
		$arts = GetOneArchive($aid);
		$art['id'] = $arts['id'];
		$art['typeid'] = $arts['typeid'];
		$art['flag'] = $arts['flag'];
		$art['click'] = $arts['click'];
		$art['title'] = $arts['title'];
		$art['url'] = $arts['arcurl'];
		$art['writer'] = $arts['writer'];
		$art['litpic'] = $arts['litpic'];
		$art['pubdate'] = $arts['pubdate'];
		$art['description'] = $arts['description'];
		$query = "select body from dede_addonarticle where aid=".$aid;
		$this->dsql->Execute('me',$query);
		$res = $this->dsql->GetOne();
		$art['body'] = $res['body'];
		return $art;
	}

}
